package com.qianbao.qianbaobusiness.ui.invoice;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.baseandroid.config.Global;
import com.baseandroid.mvp.BaseMvpActivity;
import com.qianbao.qianbaobusiness.R;
import com.qianbao.qianbaobusiness.json.GStoreBean;
import com.qianbao.qianbaobusiness.json.MerchantInfo;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author: Routee
 * @date 2018/6/20
 * @mail wangc4@qianbaocard.com
 * ------------1.本类由Routee开发,阅读、修改时请勿随意修改代码排版格式后提交到git。
 * ------------2.阅读本类时，发现不合理请及时指正.
 * ------------3.如需在本类内部进行修改,请先联系Routee,若未经同意修改此类后造成损失本人概不负责。
 */
public class ContractStoreListActivity extends BaseMvpActivity<ContractStoreListView, ContractStoreListPresenter> implements ContractStoreListView {

    @BindView(R.id.tv_title)
    TextView     mTvTitle;
    @BindView(R.id.rv)
    RecyclerView mRv;

    private List<GStoreBean.ResultBean> mList;
    private StoreContractListRvAdapter  mRvAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_contract_store_list;
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected void setupView() {
        initData();
        initView();
    }

    private void initData() {
        if (mList == null) {
            mList = new ArrayList<>();
        } else {
            mList.clear();
        }
        for (MerchantInfo bean : Global.getShopListInfo().merchantList) {
            GStoreBean.ResultBean b = new GStoreBean.ResultBean();
            b.setGroupName(bean.merchantName);
            b.setGroupNo(bean.merchantNo);
            b.setAddress(bean.shopProviceName + "-" + bean.shopCityName + "-" + bean.shopDistrictName);
            mList.add(b);
        }
        if (GStoreConstant.getmGStoreBean().getResult() != null) {
            mList.addAll(GStoreConstant.getmGStoreBean().getResult());
        }
        mRv.setLayoutManager(new LinearLayoutManager(this));
        if (mRvAdapter == null) {
            mRvAdapter = new StoreContractListRvAdapter(this);
        }
        mRv.setAdapter(mRvAdapter);
        mRvAdapter.resetData(mList);
        mRvAdapter.setClickListener(new StoreContractListRvAdapter.ClickListener() {
            @Override
            public void itemClicked(String merchantNo, String merchantName) {
                Intent intent = new Intent(ContractStoreListActivity.this, ContractListActivity.class);
                intent.putExtra("merchantName", merchantName);
                intent.putExtra("merchantNo", merchantNo);
                startActivity(intent);
            }
        });
    }

    private void initView() {
        mTvTitle.setText("电子合同");
    }

    @Override
    protected void setupData(Bundle savedInstanceState) {

    }

    @OnClick(R.id.iv_back_toolbar)
    public void onViewClicked() {
        finish();
    }
}
